﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;

namespace GUI
{
    public partial class ThucDon : Form
    {
        public ThucDon()
        {
            InitializeComponent();
            
            cbbTuan.DisplayMember = "ID_Tuan";
            cbbTuan.ValueMember = "ID_Tuan";
            if (CauHinh.chedo == 0)
            {
                loai = 0;
            }
            else
            {
                loai = 1;
            }
        }

        public int loai;
        private void ThucDon_Load(object sender, EventArgs e)
        {
            DuaDSTuan_cbb();

        }

        //Lay danh sach tuan
        void DuaDSTuan_cbb()
        {
            ThucDon_BUS tuan = new ThucDon_BUS();            
            DataSet dts = new DataSet();
            dts = tuan.Tuan_dts(loai);
                    
            cbbTuan.DataSource = dts.Tables[0];
           


        }
        //Lay danh sach ngay theo tuan
        void DuaDSNgay_cbb()
        {
            ThucDon_BUS ngay = new ThucDon_BUS();
            DataSet dts = new DataSet();
            int tuan = (int)cbbTuan.SelectedValue;
            dts = ngay.Ngay_dts(loai, tuan);
            cbbNgay.DataSource = dts.Tables[0];
            cbbNgay.DisplayMember = "ID_Ngay";
            cbbNgay.ValueMember = "ID_Ngay";
        }
        // Lay danh sach thuc don theo tuan va ngay
        void DuaDSThucdon()
        {
            ThucDon_BUS dstd = new ThucDon_BUS();
            DataSet dts = new DataSet();
            int tuan = (int)cbbTuan.SelectedValue;
            int ngay = (int)cbbNgay.SelectedValue;
            dts = dstd.DSThucdon_TuanNgay(loai, tuan, ngay);
            DataTable dt = new DataTable();
            try
            {
                dt = dts.Tables[0];
                dgvDSTD.Rows.Clear();
                //Dua danh sach vao dataview
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string ID_tuan = dt.Rows[i]["ID_Tuan"].ToString();
                    string Ngay = dt.Rows[i]["ID_Ngay"].ToString();
                    string Ten_Nhom = dt.Rows[i]["TenNhom"].ToString();
                    string TenMonAn = dt.Rows[i]["TenMonAn"].ToString();
                    dgvDSTD.Rows.Add(ID_tuan, Ngay, Ten_Nhom, TenMonAn);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            DuaDSThucdon();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void cbbTuan_SelectedIndexChanged(object sender, EventArgs e)
        {
            DuaDSNgay_cbb();
        }

        private void bttDelete_Click(object sender, EventArgs e)
        {
            int tuan = (int)cbbTuan.SelectedValue;
            int ngay = (int)cbbNgay.SelectedValue;
            ThucDon_BUS td = new ThucDon_BUS();
            td.Delete_ThuDon(loai, tuan, ngay);
            MessageBox.Show("Delete is susscess...");
            DuaDSTuan_cbb();
            dgvDSTD.Rows.Clear();
            DuaDSThucdon();
        }
    }
}
